package com.clstu.properties;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

public class Properties03 {
    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();//是Hashtable 的子类
       // properties.load(new FileReader("src\\mysql.properties"));

        /*
        public synchronized Object setProperty(String key, String value) {//底层其实用的是Hashtable，用的它的put方法
            return put(key, value);
        }

        public synchronized V put(K key, V value) {
            // Make sure the value is not null
            if (value == null) {
                throw new NullPointerException();
            }

            // Makes sure the key is not already in the hashtable.
            Entry<?,?> tab[] = table;
            int hash = key.hashCode();
            int index = (hash & 0x7FFFFFFF) % tab.length;
            @SuppressWarnings("unchecked")
            Entry<K,V> entry = (Entry<K,V>)tab[index];
            for(; entry != null ; entry = entry.next) {
                if ((entry.hash == hash) && entry.key.equals(key)) {
                    V old = entry.value;
                    entry.value = value;
                    return old;
                }
            }
    
            addEntry(hash, key, value, index);
            return null;
        }
         */
        properties.setProperty("charSet","utf-8");
        properties.setProperty("name","tom");
        properties.setProperty("pwd","999999999");
        properties.store(new FileWriter("src\\mysql01.properties"),"hello world");//hello world表示的是注释（解释配置文档）
        //用store方法写入到磁盘中
        System.out.println("配置文件保存成功············");

    }
}
